package com.winchain.chainbill.bill.biz.repurchase.cmd;

import com.shell.bee.acct.transaction.po.AcctTxRec;
import com.shell.framework.command.CallbackContext;
import com.shell.framework.command.CommandContext;
import com.shell.framework.command.ICallback;
import com.shell.framework.command.ICommand;
import com.winchain.chainbill.bill.base.po.CbDct;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.base.po.CbRpur;
import com.winchain.chainbill.bill.base.po.CbSnd;
import com.winchain.chainbill.bill.base.service.CbDctService;
import com.winchain.chainbill.bill.base.service.CbSndService;
import com.winchain.chainbill.bill.biz.Bill;
import com.winchain.chainbill.bill.biz.discount.service.impl.BillDctFinQuotaService;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BillRpurDctFinQuotaCmd implements ICommand<Bill<CbRpur>>, ICallback<Bill<CbRpur>, AcctTxRec> {
	@Autowired
	private CbSndService cbSndService;
	@Autowired
	private BillDctFinQuotaService billDctFinQuotaService;
	@Autowired
	private CbDctService cbDctService;

	public boolean execute(CommandContext<Bill<CbRpur>> context) throws Exception {
		Bill<CbRpur> bill = (Bill) context.getSource();
		CbRec rec = bill.getRec();
		CbSnd snd = this.cbSndService.getBillSndById(rec.getRootId());
		List<String> dctStates = new ArrayList();
		dctStates.add("1");
		dctStates.add("2");
		CbDct dct = this.cbDctService.selectDctByBillIdAndStates(rec.getBillId(), dctStates);
		this.billDctFinQuotaService.trade(rec, snd, dct, "qt_res", "������������");
		return false;
	}

	public boolean callback(CallbackContext<Bill<CbRpur>, AcctTxRec> context) throws Exception {
		execute(context);
		return false;
	}
}
